var e = getApp();

Page({
    data: {
        order_id: "",
        invoice_type: "",
        invoice_title: "",
        order_number: "",
        rise_type: "",
        dowm: "",
        email: !1
    },
    onLoad: function(e) {
        e.order_id && this.setData({
            order_id: e.order_id
        });
    },
    onReady: function() {},
    onShow: function() {
        this._initData(), this._getInvoiceDet(), this._initDownload();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    _initData: function() {
        this.setData({
            invoice_type: "",
            invoice_title: "",
            order_number: "",
            rise_type: "",
            dowm: ""
        });
    },
    _getInvoiceDet: function() {
        var t = this, i = e.getNetAddresss("order.detail");
        i += "&order_id=" + this.data.order_id, e._getNetWork({
            url: i,
            success: function(e) {
                var i = e.data;
                1 == i.result && t.setData({
                    invoice_type: i.data.invoice_type ? "纸质发票" : "电子发票",
                    rise_type: i.data.invoice_state ? "已开票" : "未开票",
                    invoice_title: i.data.collect_name,
                    order_number: i.data.order_sn,
                    email: i.data.email || !1
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _initDownload: function() {
        var t = this, i = e.getNetAddresss("order.rise.get-invoice");
        i += "&order_id=" + this.data.order_id, e._getNetWork({
            url: i,
            success: function(e) {
                var i = e.data;
                1 == i.result && t.setData({
                    dowm: i.data.invoice
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    checkInvoice: function() {
        var t = this, i = e.getNetAddresss("order.rise.get-invoice");
        i += "&order_id=" + this.data.order_id, e._getNetWork({
            url: i,
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    var o = [];
                    i.data.invoice && o.push(i.data.invoice), ".pdf" == t.getExtension(i.data.invoice) ? wx.downloadFile({
                        url: o[0],
                        success: function(e) {
                            console.log(e);
                            var t = e.tempFilePath;
                            wx.openDocument({
                                filePath: t,
                                success: function(e) {
                                    console.log("打开文档成功");
                                }
                            });
                        }
                    }) : o.length > 0 && wx.previewImage({
                        current: o[0],
                        urls: o
                    });
                }
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getExtension: function(e) {
        return e.substring(e.lastIndexOf("."));
    }
});